package ImgCombine;

import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;
import javax.imageio.ImageIO;
import XmlLoader.*;

public class Test 
{
	public static void main(String[] args) 
	{
		int indexRow = 0, indexCol = 0;
		//set background image
		BufferedImage img_background = null, img_inserted = null;
		//set inserted-start position
		Position pos_startInsert = new Position();
		pos_startInsert.x = 2;
		pos_startInsert.y = 51;
		//set file name of inserted image
		String fileName_insertedImg = Constant.FILENAME_IMG_FORM;
		fileName_insertedImg = fileName_insertedImg.replace("aaaaa", FGObjProcess.ACT005_numFormat("0"));
		fileName_insertedImg = fileName_insertedImg.replace("bbbbb", FGObjProcess.ACT005_numFormat("0"));
		try 
		{
			//read image-background
			img_background = ImageIO.read(new File(Constant.FILENAME_IMG_BACKGROUND));
			//read inserted image
			img_inserted = ImageIO.read(new File(fileName_insertedImg));
			//start to insert image to background
			indexRow = 0;
			while(indexRow < img_inserted.getHeight())
			{
				indexCol = 0;
				while(indexCol < img_inserted.getWidth())
				{
					img_background.setRGB(indexCol + pos_startInsert.x, indexRow + pos_startInsert.y, 
					    img_inserted.getRGB(indexCol, indexRow));
					indexCol = indexCol + 1;
				}
				indexRow = indexRow + 1;
			}
			//write to file
			ImageIO.write(img_background, "jpg", new File("InsertResult.jpg"));
		} 
		catch (IOException e) 
		{
			System.out.println("No Image");
		}
	}
}
